#ifndef _BROADCAST_PROTO_H_
#define _BROADCAST_PROTO_H_

#include "vpi.h"

#define BROADCAST_PROTO_TYPE  0x8004
#define BROADCAST_PROTO_NAME  "broadcast"
#define BROADCAST_PROTO_VER   "2.1.4"

extern const sproto_header * broadcast_default_header;
//============================================================================
// BROADCAST协议
/* protocol spec */
#define IS_BROADCAST_DOWNCMD(cmd) ((cmd)>0x59&&(cmd)<0x65) 
#define IS_BROADCAST_UPCMD(cmd) ((cmd)>0x70&&(cmd)<0x76) 

#define BROADCAST_TOP_1			0x40
#define BROADCAST_TOP_2			0x21
#define BROADCAST_END			0x23

// down cmd
#define BROADCAST_GET_STATUS	0x60
#define BROADCAST_SET_STATUS	0x61
#define BROADCAST_GET_CODE		0x62
#define BROADCAST_GET_P2P       0x63
#define BROADCAST_SET_NET_PARAS 0x64

// up cmd
#define BROADCAST_RES_STATUS	0x71
#define BROADCAST_RES_SETOK		0x72
#define BROADCAST_RES_CODE		0x73
#define BROADCAST_RES_P2P  		0x74
#define BROADCAST_RES_NET		0x75

#define DHCP_STATUS_ON  0x01 // 0x31
#define DHCP_STATUS_OFF 0x02 // 0x32
//============================================================================
//down cmd
typedef struct dev_ip_conf
{
	char id[12];
	char ip[16];
	char subnet[16];
	char gwip[16];
	char dnsip[16];
	char username[16];
	char code[16];
}sdev_ip_conf;
typedef struct dev_net_param
{
	char id[12];
	unsigned char dhcp_flag;
	unsigned short stream_port;
	unsigned short web_port;
}sdev_net_param;

typedef union broadcast_down_content
{
	int get_status_dummy;
	sdev_ip_conf set_status;
	char get_ident_domain[32];
	int get_broadcast_dummy;
	sdev_net_param set_net_para;
}ubroadcast_down_content;

// up cmd
typedef struct dev_status_
{
	char id[12];
	char ip[16];
	char subnet[16];
	char gwip[16];
	char dnsip[16];
	char version[16];
	unsigned short web_port;
	char macaddr[32];
	unsigned short stream_port;
	unsigned char dhcp_flag;
}sdev_status;
typedef struct dev_entry
{
	char id[12];
	char name[32];
	char code[16];
}sdev_entry;
typedef union broadcast_up_content
{
	sdev_status res_dev_status;
	char res_setok_id[12];
	sdev_entry res_get_code;
	sdev_status res_p2p_status;
	char res_setnet_id[12];
}ubroadcast_up_content;


typedef struct broadcast_content
{
	ubroadcast_down_content down_content;
	ubroadcast_up_content   up_content;
}sbroadcast_content;

// 构建报文接口
int broadcast_build_package(eproto_role role,sproto_msg *pmsg,unsigned char *sendbuff, int *len);

// 解析报文接口
int broadcast_parse_package(eproto_role role,sproto_msg *pmsg,unsigned char *recvbuff, int len);

#endif

